<?php
/*
	
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();

if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['code1'])){
		$params['code1']=trim($_RQ['code1']);
		$return['params']['code1']=$params['code1'];
	
	$fields=array('id','createtime','awardinfo','awardTime','code1','gameId','rid','awardLevel','award','ausername','awardstatus');
	$parameter=array('params'=>$params,'limit'=>array($pindex,$psize),'fields'=>$fields,'orderby'=>'id desc');
	$list=$this->get_list('award',$parameter,$total);
	}
	if($list){
		foreach($list as &$item){
			
			$item['title'] = pdo_getcolumn('jy_h5game_reply',array('id'=>$item['rid']),'title');
			
			
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['awardstatus'] =array('1'=>'未核销','2'=>'已核销');
	
	$return['htmls']=array (
		  'type' => 'list',
		  'tabs' => 
		  array(
            array('op' => 'list','title' => '前往核销',),
		  ),
		  'list' => 
		  array ('data' => 'list','list' => 
		    array(
			 array('name' => 'code1','type' => 'string','title' => '劵码',),
			 array('name' => 'rid','type' => 'string','title' => '活动编号',),
			 array('name' => 'title','type' => 'string','title' => '活动名称',),
			 array('name' => 'awardLevel','type' => 'string','title' => '奖项等级',),
		     array('name' => 'award','type' => 'string','title' => '奖品名称',),
		     array('name' => 'awardinfo','type' => 'string','title' => '中奖者',),
			 array('name' => 'awardTime','type' => 'time','title' => '中奖时间',),   
			 array('name' => 'awardstatus','type' => 'radio','title' => '卷码状态','options'=>'awardstatus'),     
			 ),
			 'delall' => false,
		       'del_one' => false,
		       'edit' => false,
			 'action'=>array(
			array('type'=>'post','op'=>'hexiao','title'=>'核销','message'=>'确定核销吗！','show'=>array('awardstatus'=>1)),
			array('type'=>'post','op'=>'unhexiao','title'=>'撤回核销','message'=>'确定撤回核销吗！','show'=>array('awardstatus'=>2))),
		  ),
		  
		  'search' => 
		  array(
		  array('name' => 'code1','width'=>'15','type' => 'string','title' => '劵码',),
		  ),
		);

	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=$this->get('category',array('id'=>$id));

	}else{
		$item=array();
	}
	$return['item']=$item;
	$return['htmls']=array (
  'type' => 'edit',
  'post' => 'post',
  'edit_tab' => '商品分类',
  'edits' => 
  array (
    0 => 
    array (
      'title' => '商品分类',
      'list' => 
      array (
        0 => 
        array (
          'name' => 'displayorder',
          'type' => 'string',
          'title' => '排序',
        ),
        1 => 
        array (
          'name' => 'name',
          'type' => 'string',
          'title' => '分类名称',
        ),
        2 => 
        array (
          'name' => 'thumb',
          'type' => 'image',
          'title' => '分类图片',
        ),
        3 => 
        array (
          'name' => 'description',
          'type' => 'text',
          'title' => '分类描述',
        ),
        4 => 
        array (
          'name' => 'isrecommand',
          'type' => 'switch',
          'title' => '是否推荐',
        ),
        5 => 
        array (
          'name' => 'enabled',
          'type' => 'switch',
          'title' => '是否显示',
        ),
      ),
    ),
  ),
);

	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array_fields(array('displayorder','name','thumb','description','isrecommand','enabled',),$post);

	$id=intval($post['id']);
	if($id){
		$this->update('category',$data,array('id'=>$id));
		exi('修改商品分类表成功！');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		$this->insert('category',$data);
		exi('新增商品分类表成功！');
	}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		$this->delete('hexiao',array('id'=>$id));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->delete('hexiao',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='hexiao'){
	$id=intval($_RQ['id']);
	if($id){
		$this->update('award',array('awardstatus'=>2),array('id'=>$id));
	}
	exi('核销成功！');
}
if($_RQ['op']=='unhexiao'){
	$id=intval($_RQ['id']);
	if($id){
		$this->update('award',array('awardstatus'=>1),array('id'=>$id));
	}
	exi('撤回核销成功！');
}